using Photon;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityStandardAssets.CrossPlatformInput;

public class TouchPad : Photon.MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IDragHandler
{
	[HideInInspector]
	public bool NowTouch;

	public float x;

	public float y;

	public float MaxY = 14f;

	private bool drag;

	private int lastDragFrameNumber;

	public string horizontalAxisName = "Mouse X";

	public string verticalAxisName = "Mouse Y";

	public static CrossPlatformInputManager.VirtualAxis m_HorizontalVirtualAxis;

	public static CrossPlatformInputManager.VirtualAxis m_VerticalVirtualAxis;

	public void CreateVirtualAxes()
	{
		m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
		CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
		m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
		CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
	}

	public void OnDrag(PointerEventData eventData)
	{
		drag = true;
		Vector3 vector = eventData.delta;
		x = vector.x;
		y = vector.y;
		lastDragFrameNumber = Time.renderedFrameCount;
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		drag = false;
		x = 0f;
		y = 0f;
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		drag = true;
		OnDrag(eventData);
	}

	private void Update()
	{
		if (drag && lastDragFrameNumber < Time.renderedFrameCount - 2)
		{
			x = 0f;
			y = 0f;
		}
		UpdateVirtualAxes(new Vector3(x, y, 0f));
	}

	private void UpdateVirtualAxes(Vector3 value)
	{
		value = value * 0.01f * 10f;
		m_HorizontalVirtualAxis.Update(value.x);
		m_VerticalVirtualAxis.Update(value.y);
	}

	private void OnDisable()
	{
	}
}
